﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace CSDemo
{
   class cmd
    {
       public static SqlConnection GetConnection(){
        SqlConnection cn = new SqlConnection("Server=.\\SA; uid=sa; pwd=123; database=TestCS");
        cn.Open();
        return cn ; 
       }

        public static void ExecuteNonquery(string sql){
        SqlCommand cmd = new SqlCommand(sql, GetConnection());
        cmd.ExecuteNonQuery();
        }

       public static object ExcecuteScalar(String sql){
        SqlCommand cmd =new SqlCommand(sql, GetConnection());
        object val = cmd.ExecuteScalar();
        return val;
       }

       public static DataTable ExcecuteDatatable(String sql){
        SqlCommand cmd= new SqlCommand(sql, GetConnection());
        SqlDataReader dr= cmd.ExecuteReader();
        DataTable dt = new DataTable();
        dt.Load(dr);
        dr.Close();
        return dt;
        }

       public static DataTable loadtable1(string sql){
        SqlDataAdapter  da = new SqlDataAdapter(sql, GetConnection());
        SqlCommandBuilder CB = new SqlCommandBuilder(da);
        DataTable dt = new DataTable();
        da.Fill(dt);
        return dt;
       }
    }
}
